package com.heima.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.common.dto.ResponseResult;
import com.heima.user.dto.FollowBehaviorDto;
import com.heima.user.entity.ApUserFollow;
import com.heima.user.mapper.ApUserFollowMapper;
import com.heima.user.service.IApUserFollowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * APP用户关注信息表 服务实现类
 * </p>
 *
 * @author PG
 * @since 2022-06-30
 */
@Service
public class ApUserFollowServiceImpl extends ServiceImpl<ApUserFollowMapper, ApUserFollow> implements IApUserFollowService {

    /**
     * 查询用户关注行为记录
     * @param dto
     * @return
     */
    @Override
    public ResponseResult<ApUserFollow> getFollow(FollowBehaviorDto dto) {
        //1. 构建查询条件
        LambdaQueryWrapper<ApUserFollow> query = new LambdaQueryWrapper<>();
        //2. 用户id 查询条件
        query.eq(ApUserFollow::getUserId, dto.getUserId());
        //3. 关注作者id 查询条件
        query.eq(ApUserFollow::getFollowId, dto.getFollowId());
        //4. plus 进行条件查询
        ApUserFollow one = this.getOne(query);
        //5. 返回给前端查询结果
        return ResponseResult.okResult(one);
    }
}
